<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://www.springframework.org/security/tags" prefix="security"%>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>工程施工实时监控系统</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">


    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!--<link rel="stylesheet" href="${pageContext.request.contextPath}/${pageContext.request.contextPath}/${pageContext.request.contextPath}/plugins/timepicker/bootstrap-timepicker.min.css">-->

    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>


    <!--<script src="${pageContext.request.contextPath}/${pageContext.request.contextPath}/${pageContext.request.contextPath}/plugins/timepicker/bootstrap-timepicker.min.js"></script>-->

    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/morris/morris.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/select2/select2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/layui/css/layui.css" media="all">
    <style>
        .content {
            padding-bottom: 25px;
        }

        /*使layui数据表格的checkbox居中*/
        .layui-table-cell .layui-form-checkbox[lay-skin="primary"] {
            top: 50%;
            transform: translateY(-50%);
        }

        .layui-form-item {
            height: 40px;
        }

        .layui-form-label {
            width: 100px;
        }

        .mylabel {
            font: 14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial, sans-serif;
            width: 50px;
        }
    </style>
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <!-- 页面头部 -->
    <jsp:include page="header.jsp"></jsp:include>
    <!-- 页面头部 /-->

    <!-- 导航侧栏 -->
    <jsp:include page="aside.jsp"></jsp:include>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <!-- @@master = admin-layout.html-->
    <!-- @@block = content -->

    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                用户管理
                <%--<small>数据列表</small>--%>
            </h1>
            <ol class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/pages/main.jsp"><i class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li class="active">用户管理</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!-- .box-body -->
            <div class="box box-primary">
                <%--新增用户表单--%>
                <div class="site-text" style="margin: 5%; display: none" id="addUserWindow" target="test123">
                    <form class="layui-form" id="book" method="post" lay-filter="example">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-block">
                                <input type="text" id="username" name="username" lay-verify="required"
                                       lay-filter="username" autocomplete="off" placeholder="请输入用户名"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-block">
                                <input type="text" id="password" name="password" lay-verify="required"
                                       autocomplete="off" placeholder="请输入密码" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-block">
                                <input type="text" id="compellation" name="compellation" lay-verify="required"
                                       autocomplete="off"
                                       placeholder="请输入姓名" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">类别</label>
                            <div class="layui-input-block">
                                <select name="systemID" id="systemID" lay-filter="leibie">
                                    <option value="0">施工单位级用户</option>
                                    <option value="1">监理单位级用户</option>
                                    <option value="2">建设单位级用户</option>
                                    <option value="3">检测单位级用户</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">类别</label>
                            <div class="layui-input-block">
                                <select name="userLevel" id="userLevel" lay-filter="zhanghuleibie">
                                    <option value="1">普通用户</option>
                                    <option value="2">管理员</option>
                                    <option value="3">超级管理员</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-block">
                                <select name="gender" id="gender" lay-filter="xingbie">
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" id="tel" name="tel" lay-verify="phone" autocomplete="off"
                                       placeholder="请输入手机号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                                <select name="state" id="state" lay-filter="xingbie">
                                    <option value="0">开启</option>
                                    <option value="1">关闭</option>
                                </select>
                            </div>
                        </div>
                        <!--  <div class="layui-form-item">
                           <div class="layui-input-block">
                             <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                           </div>
                         </div> -->
                    </form>
                </div>
                <%--end新增用户表单--%>
                <%--标段权限分配表单--%>
                <div class="site-text" style="margin: 5%; display: none" id="editSectionWindow" target="test123">
                    <form class="layui-form" id="section" method="post" lay-filter="menu">
                        <div class="layui-collapse" id="department"></div>
                    </form>
                </div>
                <%--end标段权限分配表单--%>
                <%--菜单权限分配表单--%>
                <div class="site-text" style="margin: 5%; display: none" id="editMenuWindow" target="test123">
                    <form class="layui-form" id="menu" method="post" lay-filter="menu">
                        <div class="layui-collapse" id="panel"></div>
                    </form>
                </div>
                <%--end菜单权限分配表单--%>
                <%--操作权限分配表单--%>
                <div class="site-text" style="margin: 5%; display: none" id="editPermissionWindow" target="test123">
                    <form class="layui-form" id="permission" method="post" lay-filter="permission">
                        <div class="layui-collapse">
                            <%--<label style='font: 14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;'>--%>
                            <%--        <input name='permissionids' lay-filter='permissionCheck' type='checkbox'
                                           lay-skin='primary' value="">小霸王
                                    <input name='permissionids' lay-filter='permissionCheck' type='checkbox'
                                           lay-skin='primary' value="">小霸王--%>
                            <%--</label>--%>
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title">用户操作</h2>
                                <div class="layui-colla-content layui-show">
                                    <input name="permissionids" lay-filter='permissionCheck' lay-skin='primary'
                                           type="checkbox" value="3" id="checkin1"/>
                                    <label for="checkin1" class="mylabel">test1</label>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input name="permissionids" lay-filter='permissionCheck' lay-skin='primary'
                                           type="checkbox" value="4" id="checkin2"/>
                                    <label for="checkin2" class="mylabel">test2</label>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input name="permissionids" lay-filter='permissionCheck' lay-skin='primary'
                                           type="checkbox" value="5" id="checkin3"/>
                                    <label for="checkin3" class="mylabel">test3</label>&nbsp;&nbsp;&nbsp;&nbsp;
                                </div>
                            </div>

                        </div>
                    </form>
                </div>
                <%--end操作权限分配表单--%>
            </div>
            <div class="demoTable">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" id="resetForm">

                    <div class="layui-inline">
                        <input class="layui-input" autocomplete="off" name="name" id="name" placeholder="请输入用户名">

                    </div>

                    <button class="layui-btn" data-type="reload">搜索</button>
                    <button class="layui-btn" id="reset">重置</button>
                    <button class="layui-btn" id="addUser" style="float:right">添加用户</button>


                    <%--</div>--%>
                </div>
            </div>
            <table class="layui-hide" id="userTable" lay-filter="userTable">

            </table>

            <script type="text/html" id="toolbarDemo">

                <%--<button class=" layui-icon-cols" lay-event="refresh">刷新</button>--%>
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editSection">标段权限分配</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editMenu">菜单权限分配</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editPermission">操作权限分配</a>
            </script>
            <script src="${pageContext.request.contextPath}/plugins/layui/layui.js" charset="utf-8"></script>
            <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- @@close -->
    <!-- 内容区域 /-->


</div>


<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>

<script>
    //主体表格
    layui.use(['table', 'layer', 'form', 'element'], function () {
        var table = layui.table;
        var form = layui.form;
        var element = layui.element;
        table.render({
            elem: '#userTable'
            , url: '/user/findAll.do'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-refresh'
            }]
            , method: 'post'
            // , totalRow: true 合计行
            , title: '用户列表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {title: '序号', align: 'center', type: 'numbers'}
                , {field: 'name', title: '用户名', width: "15%", edit: 'text', align: "center"}
                , {
                    field: 'systemID',
                    title: '类别',
                    width: "15%",
                    edit: 'text',
                    align: "center",
                    templet: function (item) {
                        if (item.systemID == 0) {
                            return "施工单位级用户";
                        } else if (item.systemID == 1) {
                            return "监理单位级用户";
                        } else if (item.systemID == 2) {
                            return "建设单位级用户";
                        } else if (item.systemID == 3) {
                            return "检测单位级用户";
                        }
                    }
                }
                , {
                    field: 'userLevel',
                    title: '等级',
                    width: "15%",
                    edit: 'text',
                    align: "center",
                    templet: function (item) {
                        if (item.userLevel == 1) {
                            return "普通用户";
                        } else if (item.userLevel == 2) {
                            return "管理员";
                        }
                        else if (item.userLevel == 3) {
                            return "超级管理员";
                        }
                    }
                }
                , {field: 'tel', title: '电话', width: "10%", edit: 'text', align: "center"}
                , {
                    field: 'state', title: '状态', width: "10%", edit: 'text', align: "center", templet: function (item) {
                        if (item.state == '0') {
                            return "开启";
                        } else if (item.state == '1') {
                            return "关闭";
                        }
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: "28%"}
            ]],
                done: function (res, curr, count) {
                    $("table").css("width", "100%");
                    //这里设置表格的宽度为100%
                },
            page: true
            , id: 'testReload'
        });
        //条件查询重载表格
        var $ = layui.$, active = {
            reload: function () {
                var name = $('#name');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        // key: {
                        name: name.val(),

                        // }
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //头工具栏事件
        table.on('toolbar(userTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    $(".layui-laypage-btn").click();
                    break;
            }
            ;
        });
        //重置
        $('#reset').on('click', function () {
            $(':input', '#resetForm')
                .not(":button", ":reset", "hidden", "submit")
                .val("")
                .removeAttr("checked")
                .removeAttr("selected");
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    name: "",
                }
            }, 'data');
        });

        //添加用户
        $("#addUser").click(function () {
            layer.open({
                type: 1,
                title: "用户基本信息",
                area: ['30%', '70%'],//窗口大小
                btn: ['确定', '取消'],//按钮
                content: $("#addUserWindow"),//对应表单
                success: function (layero) {
                    // 解决按enter键重复弹窗问题
                    $(':focus').blur();
                    // 添加form标识
                    layero.addClass('layui-form');
                    // 将保存按钮改变成提交按钮
                    layero.find('.layui-layer-btn0').attr({
                        'lay-filter': 'book',
                        'lay-submit': ''
                    });
                    // 表单验证
                    /*    form.verify({
                            username : function(value, item) {
                                if (!new RegExp("^[a-zA-Z0-9_|\u4e00-\u9fa5\]{2,10}$")
                                    .test(value)) {
                                    return '角色名必须为2-10位且不能有特殊字符';
                                }
                            },
                        });*/
                    // 刷新渲染(否则开关按钮会不显示)
                    form.render('checkbox');
                },
                yes: function (index, layero) {
                    // console.log($('#compellation').val());
                    // 监听提交按钮
                    form.on('submit(book)', function (data) {
                        $.ajax({
                            type: "post",
                            url: "/user/save.do",
                            data: {
                                username: $('#username').val(),
                                password: $('#password').val(),
                                name: $('#compellation').val(),
                                systemID: $('#systemID').val(),
                                userLevel: $('#userLevel').val(),
                                gender: $('#gender').val(),
                                tel: $('#tel').val(),
                                state: $('#state').val()
                            },
                            success: function (Data) {
                                if (Data.result) {
                                    layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                        $("#book")[0].reset()//重置form
                                    })
                                    table.reload('testReload', {//重载表格
                                        page: {
                                            curr: 1
                                        }
                                    })
                                } else {
                                    layer.msg(Data.msg)
                                }
                            }, error: function () {
                                layer.alert("服务器错误", {icon: 1, title: '提示'}, function (i) {
                                    layer.close(i);
                                    layer.close(index);//关闭弹出层
                                    $("#book")[0].reset()//重置form
                                })
                            }
                        })
                    });
                }

            });
        })

        //监听行工具事件
        table.on('tool(userTable)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type: "post",
                        url: "/user/del.do",
                        data: {
                            id: obj.data.id
                        },
                        success: function (Data) {
                            if (Data.result) {
                                layer.msg("删除成功");
                                obj.del();//删除当前行
                                layer.close(index);//关闭弹出层
                            } else {
                                layer.msg("删除失败");
                                layer.close(index);//关闭弹出层

                            }
                        }, error: function () {
                            layer.msg("删除失败");
                            layer.close(index);//关闭弹出层
                        }
                    })
                });

            } else if (obj.event === 'edit') {
                layer.open({
                        type: 1,
                        title: "用户基本信息",
                        area: ['30%', '70%'],//窗口大小
                        btn: ['确定', '取消'],//按钮
                        content: $("#addUserWindow"),//对应表单
                        success: function (index, layero) {
                            $('#username').val(obj.data.username);
                            $('#password').attr('placeholder', "不输入则不修改密码");
                            $('#compellation').val(obj.data.name);
                            $('#systemID').val(obj.data.systemID);
                            $('#userLevel').val(obj.data.userLevel);
                            $('#tel').val(obj.data.tel);
                            $('#state').val(obj.data.state);

                            form.render('select');//刷新select
                        }, yes: function (index, layero) {
                            // 监听提交按钮
                            $.ajax({
                                type: "post",
                                url: "/user/update.do",
                                data: {
                                    id: obj.data.id,
                                    username: $('#username').val(),
                                    password: $('#password').val(),
                                    name: $('#compellation').val(),
                                    systemID: $('#systemID').val(),
                                    userLevel: $('#userLevel').val(),
                                    gender: $('#gender').val(),
                                    tel: $('#tel').val(),
                                    state: $('#state').val()
                                },
                                success: function (Data) {
                                    if (Data.result) {
                                        layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                            layer.close(i);
                                            layer.close(index);//关闭弹出层
                                            $("#book")[0].reset()//重置form
                                        })
                                        table.reload('testReload', {//重载表格
                                            page: {
                                                curr: 1
                                            }
                                        })
                                    } else {
                                        layer.alert("修改失败", {icon: 1, title: '提示'}, function (i) {
                                            layer.close(i);
                                            layer.close(index);//关闭弹出层
                                        })
                                    }
                                }, error: function () {
                                    layer.alert("服务器错误", {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                    })
                                }
                            })
                        }, end: function () {
                            $("#book")[0].reset()//重置form
                        }
                    }
                )
            } else if (obj.event === 'editSection') {
                layer.open({
                    type: 1,
                    title: "用户标段权限",
                    area: ['30%', '60%'],//窗口大小
                    btn: ['确定', '取消'],//按钮
                    content: $("#editSectionWindow"),//对应表单
                    success: function (layero) {
                        //弹窗打开后首先清空内容,避免多次ajax操作jquery重复添加
                        $("#department").empty();
                        $.ajax({
                            type: "post",
                            url: "/user/getSectionPower.do",
                            data: {
                                id: obj.data.id
                            },
                            success: function (Data) {
                                if (Data) {
                                    var html = "";
                                    for (var i = 0; i < Data.length; i++) {
                                        html = '<div class="layui-colla-item">\n' +
                                            '                                <h2 class="layui-colla-title">' + Data[i].projectName + '</h2>\n' +
                                            '                                <div class="layui-colla-content layui-show" id="div' + i + '"></div>\n' +
                                            '                            </div>';
                                        $('#department').append(html);
                                        var child = Data[i].sectionList;
                                        for (var j = 0; j < child.length; j++) {
                                            /*    if (child[j].choose == 0) {
                                                    $("#div" + i).append( "<input name='items'lay-filter='menuCheck' type='checkbox'lay-skin='primary'  value="
                                                        + child[j].id
                                                        + ">"+"<label  >"
                                                        + child[j].menuName
                                                        + "</label>" + "&nbsp;&nbsp;"
                                                    );

                                                } else if (child[j].choose == 1) {
                                                    $("#div" + i).append("<label  style='font: 14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;'>"
                                                        + "<input name='items'lay-filter='menuCheck' checked ='checked' type='checkbox'lay-skin='primary'  value="
                                                        + child[j].id
                                                        + ">"
                                                        + child[j].menuName
                                                        + "</label>" + "&nbsp;&nbsp;"
                                                    );
                                                }*/
                                            if (child[j].choose == 0) {
                                                $("#div" + i).append("<input name='choice'lay-filter='sectionCheck' type='checkbox'lay-skin='primary'  value="
                                                    + child[j].id
                                                    + ">"
                                                    + child[j].sectionName
                                                    + "&nbsp;&nbsp;"
                                                );

                                            } else if (child[j].choose == 1) {
                                                $("#div" + i).append("<input name='choice'lay-filter='sectionCheck' checked ='checked' type='checkbox'lay-skin='primary'  value="
                                                    + child[j].id
                                                    + ">"
                                                    + child[j].sectionName
                                                    + "&nbsp;&nbsp;"
                                                );
                                            }
                                        }
                                    }
                                    form.render();//渲染页面
                                    element.render();//渲染折叠面板
                                }

                            }, error: function () {
                                layer.msg("获取菜单列表失败,请联系系统管理员")
                            }
                        })
                        form.on('checkbox(sectionCheck)', function (data) {
                            /*   if (data.elem.checked) {
                                   data.elem.checked = false;
                               } else {
                                   data.elem.checked = true;
                               }*/
                            // console.log(data.elem); //得到checkbox原始DOM对象
                            // console.log(data.elem.checked); //是否被选中，true或者false
                            // console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                            // console.log(data.othis); //得到美化后的DOM对象
                        });
                    }, yes: function (index, layero) {
                        if ($("input[name='choice']:checked").length > 0) {
                            //创建数组保存选中的checkbox的id
                            var arr = [];
                            //遍历选中的checked;
                            $("input[name='choice']:checked").each(function () {
                                //遍历存入数组中
                                arr.push($(this).val());
                            });
                        }
                        $.ajax({
                            type: "get",
                            url: "/user/userCorrelationSection.do",
                            traditional: true,//这条必须加上，否则传不了数组
                            data: {
                                sectionIds: arr,
                                userId: obj.data.id
                            },
                            success: function (Data) {
                                if (Data.result) {
                                    layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                        // location.reload();//点击确认后刷新当前页面
                                    })
                                } else {
                                    layer.msg("修改错误");
                                    layer.close(index);//关闭弹出层
                                }
                            },
                            error: function () {
                                layer.msg("服务器错误");
                                layer.close(index);//关闭弹出层
                            }
                        })
                    }
                })
            } else if (obj.event === 'editMenu') {
                layer.open({
                    type: 1,
                    title: "用户菜单权限",
                    area: ['30%', '60%'],//窗口大小
                    btn: ['确定', '取消'],//按钮
                    content: $("#editMenuWindow"),//对应表单
                    success: function (layero) {
                        //弹窗打开后首先清空内容,避免多次ajax操作jquery重复添加
                        $("#panel").empty();
                        $.ajax({
                            type: "post",
                            url: "/user/getMenuPower.do",
                            data: {
                                id: obj.data.id
                            },
                            success: function (Data) {
                                var html = "";
                                for (var i = 0; i < Data.length; i++) {
                                    html = '<div class="layui-colla-item">\n' +
                                        '                                <h2 class="layui-colla-title">' + Data[i].menuName + '</h2>\n' +
                                        '                                <div class="layui-colla-content layui-show" id="d' + i + '"></div>\n' +
                                        '                            </div>';
                                    $('#panel').append(html);
                                    var child = Data[i].child;
                                    for (var j = 0; j < child.length; j++) {
                                        /*    if (child[j].choose == 0) {
                                                $("#div" + i).append( "<input name='items'lay-filter='menuCheck' type='checkbox'lay-skin='primary'  value="
                                                    + child[j].id
                                                    + ">"+"<label  >"
                                                    + child[j].menuName
                                                    + "</label>" + "&nbsp;&nbsp;"
                                                );

                                            } else if (child[j].choose == 1) {
                                                $("#div" + i).append("<label  style='font: 14px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;'>"
                                                    + "<input name='items'lay-filter='menuCheck' checked ='checked' type='checkbox'lay-skin='primary'  value="
                                                    + child[j].id
                                                    + ">"
                                                    + child[j].menuName
                                                    + "</label>" + "&nbsp;&nbsp;"
                                                );
                                            }*/
                                        if (child[j].choose == 0) {
                                            $("#d" + i).append("<input name='items'lay-filter='menuCheck' type='checkbox'lay-skin='primary'  value="
                                                + child[j].id
                                                + ">"
                                                + child[j].menuName
                                                + "&nbsp;&nbsp;"
                                            );

                                        } else if (child[j].choose == 1) {
                                            $("#d" + i).append("<input name='items'lay-filter='menuCheck' checked ='checked' type='checkbox'lay-skin='primary'  value="
                                                + child[j].id
                                                + ">"
                                                + child[j].menuName
                                                + "&nbsp;&nbsp;"
                                            );
                                        }
                                    }
                                }
                                form.render();//渲染页面
                                element.render();//渲染折叠面板
                            }, error: function () {
                                layer.msg("获取菜单列表失败,请联系系统管理员")
                            }
                        })
                        form.on('checkbox(menuCheck)', function (data) {
                            /*   if (data.elem.checked) {
                                   data.elem.checked = false;
                               } else {
                                   data.elem.checked = true;
                               }*/
                            // console.log(data.elem); //得到checkbox原始DOM对象
                            // console.log(data.elem.checked); //是否被选中，true或者false
                            // console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                            // console.log(data.othis); //得到美化后的DOM对象
                        });
                    }, yes: function (index, layero) {
                        if ($("input[name='items']:checked").length > 0) {
                            //创建数组保存选中的checkbox的id
                            var arr = [];
                            //遍历选中的checked;
                            $("input[name='items']:checked").each(function () {
                                //遍历存入数组中
                                arr.push($(this).val());
                            });
                        }
                        $.ajax({
                            type: "get",
                            url: "/user/userCorrelationMenu.do",
                            traditional: true,//这条必须加上，否则传不了数组
                            data: {
                                menuIds: arr,
                                userId: obj.data.id
                            },
                            success: function (Data) {
                                if (Data.result) {
                                    layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                        // location.reload();//点击确认后刷新当前页面
                                    })
                                } else {
                                    layer.msg("保存错误");
                                    layer.close(index);//关闭弹出层
                                }
                            },
                            error: function () {
                                layer.msg("服务器错误");
                                layer.close(index);//关闭弹出层
                            }
                        })
                    }
                })
            } else if (obj.event === 'editPermission') {
                layer.open({
                    type: 1,
                    title: "用户操作权限",
                    area: ['20%', '45%'],//窗口大小
                    btn: ['确定', '取消'],//按钮
                    content: $("#editPermissionWindow"),//对应表单
                    success: function (layero) {
                        // $("#checkin2").prop("checked",true);
                        $.ajax({
                            type: "get",
                            url: "/user/getPermissionPower.do",
                            traditional: true,//这条必须加上，否则传不了数组
                            data: {
                                userId: obj.data.id
                            },
                            success: function (Data) {
                                if (Data) {
                                    $("input[name='permissionids']:not(:checked)").each(function () {
                                        var checkId = $(this).val();
                                        for (var i = 0; i < Data.length; i++) {
                                            var permissionId = Data[i];
                                            if (checkId == permissionId) {
                                                $(this).prop("checked", true);
                                            }
                                        }
                                    });
                                }
                                form.render();//渲染页面
                                element.render();//渲染折叠面板
                            }
                        })

                    }, yes: function (index, layero) {
                        if ($("input[name='permissionids']:checked").length > 0) {
                            //创建数组保存选中的checkbox的id
                            var arr = [];
                            //遍历选中的checked;
                            $("input[name='permissionids']:checked").each(function () {
                                //遍历存入数组中
                                arr.push($(this).val());
                            });
                        }
                        $.ajax({
                            type: "get",
                            url: "/user/userCorrelationPermission.do",
                            traditional: true,//这条必须加上，否则传不了数组
                            data: {
                                permissionIds: arr,
                                userId: obj.data.id
                            },
                            success: function (Data) {
                                if (Data.result) {
                                    layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                        location.reload();//点击确认后刷新当前页面
                                    })
                                } else {
                                    layer.msg(Data.msg);
                                    layer.close(index);//关闭弹出层
                                }
                            },
                            error: function () {
                                layer.msg("服务器错误");
                                layer.close(index);//关闭弹出层
                            }
                        })
                    }
                })
            }
        });
    });


    $(document).ready(function () {
        // 选择框
    /*    $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });*/
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function () {

        // 激活导航位置
        setSidebarActive("admin-datalist");

/*        // 列表按钮
        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function () {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });*/

    });

</script>
</body>

</html>
